const RongIMLib = require('@/static/js/IMSDK/RongIMLib-3.0.7-dev');
export default {
	data () {
		return {
			totalUnreadCount: 0,
			data:{},
			plancount: 0,
			healthRank:'', //1健康管理师  2专家
		}
	},
	onLoad() {
		
	},
	onShow() {
		const _this = this;
		if (!localStorage.userInfo) {
			uni.navigateTo({
				url: '/pages/login/index'
			})
		}
		_this.$api.findByHealthId().then((res)=>{
			_this.data = res.data.result;
		})
		localStorage.removeItem('memberInformationTcm');
		localStorage.removeItem('calculatePoints');
		_this.$api.InterventionPlanList({pageNum: 1,pageSize: 20,planType: 'isToday',}).then((res) => {
			if (res.data.returnCode == 200) {
				_this.plancount = res.data.result.count
			}
		})
		setTimeout(()=>{
			_this.context = uni.createInnerAudioContext();
			_this.context.src = '/static/dingdong.mp3';
			_this.$im.watch({
				message: function(event){
					_this.$im.Conversation.getTotalUnreadCount().then(function(totalUnreadCount) {
					  _this.totalUnreadCount = totalUnreadCount
					});
					var message = event.message;
					if(!message.content.content){
						// 已读通知return
						return;
					}
					_this.$im.Conversation.getList({count: 30}).then(function(conversationList) {
					   const nowUser = conversationList.filter(a=>{
						   return a.targetId == message.senderUserId
					   })
					   if(nowUser[0].notificationStatus != 2){
						   return;
					   }
					   _this.context.play()
					});
				},
				status: function(event){
					var status = event.status;
				}
			})
			_this.$im.Conversation.getTotalUnreadCount().then(function(totalUnreadCount) {
			  _this.totalUnreadCount = totalUnreadCount
			});
		},800)
		_this.healthRank = localStorage.getItem('userInfo') && JSON.parse(localStorage.getItem('userInfo')).healthRank;
	},
	methods: {
		setUp() {
			uni.navigateTo({
				url:'/pages/headFeatures/settings/settings'
			})
		},
		txl() {
			uni.navigateTo({
				url:'/pages/headFeatures/mail/list'
			})
		},
		newMember() {
			if(this.healthRank == 1) {
				uni.navigateTo({
					url:'/pages/quickly/user/adduser'
				})
			}else {
				uni.showToast({
					title:'健康管理师权限',
					icon:'none'
				})
			}
		},
		applyMember() {
			if(this.healthRank == 1) {
				uni.navigateTo({
					url:'/pages/quickly/apply/applylist'
				})
			}else {
				uni.showToast({
					title:'健康管理师权限',
					icon:'none'
				})
			}
		}
	}
}